// 引入路径处理模块
const util = require('../utils/index')
const express = require('express')
// 创建路由对象
const router = express.Router()

//添加图片
router.post("/upload", util.upload.single("file"), (req, res) => {
    console.log("收到图片")
    //接收上传文件数据 
    if (req.file) {
        let imgUrl = "/uploads/"+req.file.filename;
        res.send({
            code:200,
            message:"图片上传成功",
            data:{
                imgUrl
            }
        })
    } else {
        res.send({
            code:400,
            message:"error no image",
            data:{}
        })
    }
})

// 将路由对象共享出去
module.exports = router